package com.zero.function;

import com.zero.util.CamelCaseUtil;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.util.List;

/**
 * 通过参数名转成成get名
 *
 * @author wuxi
 * @date 2020-07-29
 */
public class ToGet implements TemplateMethodModelEx {

    @Override
    public Object exec(List list) throws TemplateModelException {
        if (list.size() != 1) {
            throw new RuntimeException("参数不合法");
        }
        String attr = list.get(0).toString();
        attr = CamelCaseUtil.convertToCamelCaseByClass(attr);
        return "get" + attr;
    }
}